#include "look1_iu16lu16n16yu8tu_6zSHy4Dc.h"
#include "rtwtypes.h"

uint8_T look1_iu16lu16n16yu8tu_6zSHy4Dc(uint16_T u0, const uint16_T bp0[], const
  uint8_T table[], uint32_T maxIndex)
{
  int32_T finalAccum;
  uint32_T iLeft;
  uint16_T frac;
  if (u0 < bp0[maxIndex]) {
    uint32_T bpIdx;
    uint32_T iRght;
    bpIdx = maxIndex >> 1U;
    iLeft = 0U;
    iRght = maxIndex;
    while (iRght - iLeft > 1U) {
      if (u0 < bp0[bpIdx]) {
        iRght = bpIdx;
      } else {
        iLeft = bpIdx;
      }

      bpIdx = (iRght + iLeft) >> 1U;
    }

    frac = bp0[iLeft];
    frac = (uint16_T)(((uint32_T)(uint16_T)((uint32_T)u0 - frac) << 16) /
                      (uint16_T)((uint32_T)bp0[iLeft + 1U] - frac));
  } else {
    iLeft = maxIndex;
    frac = 0U;
  }

  if (iLeft == maxIndex) {
    finalAccum = table[iLeft] << 23;
  } else {
    uint8_T yL_0d0;
    yL_0d0 = table[iLeft];
    finalAccum = (((int16_T)(table[iLeft + 1U] - yL_0d0) * frac) << 7) + (yL_0d0
      << 23);
  }

  return (uint8_T)(finalAccum >> 23);
}
